package net.zjitc.servlet;

import net.zjitc.domain.User;
import net.zjitc.service.ProductService;
import net.zjitc.service.UserService;
import net.zjitc.service.impl.UserServiceImpl;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

/**
 * @Author admin
 * @Date 2019/3/5 10:33
 */
@WebServlet(name = "UserServlet",urlPatterns = "/user")
public class UserServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        User user = new User();
        String uid = request.getParameter("uid");
        try {
            BeanUtils.populate(user,request.getParameterMap());
            UserService service = new UserServiceImpl();
            service.update(user,uid);
        } catch (Exception e) {
            e.printStackTrace();
        }
        request.getRequestDispatcher("/user.jsp").forward(request,response);
    }
}
